package com.pacifictextiles.qc.inspection.server.controller.servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.pacifictextiles.qc.inspection.server.model.dao.impl.RollDAOImpl;
import com.pacifictextiles.qc.inspection.server.model.vo.Roll;

/**
 * Servlet implementation class FinishRollSVL
 */
public class FinishRollSVL extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public FinishRollSVL() {
		super();

	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		response.setContentType("text/plain");
		response.setCharacterEncoding("UTF-8");

		try {

			// 获取请求参数
			Roll roll = new Roll();

			roll.setRollNo(request.getParameter("rollNo"));

			roll.setCpi(Float.parseFloat(request.getParameter("cpi")));

			roll.setDefectCount(Integer.parseInt(request
					.getParameter("defectCount")));

			roll.setExpRollNo(request.getParameter("expRollNo"));

			roll.setFabricWeight(Float.parseFloat(request
					.getParameter("fabricWeight")));

			roll.setFullCode(request.getParameter("fullCode"));

			roll.setInspectStatus(Boolean.parseBoolean(request
					.getParameter("inspectStatus")));

			roll.setNetLength(Float.parseFloat(request
					.getParameter("netLength")));

			roll.setQualityLevel(Integer.parseInt(request
					.getParameter("qualityLevel")));

			roll.setSpace(Float.parseFloat(request.getParameter("space")));

			roll.setTotalpoints(Integer.parseInt(request
					.getParameter("totalPoints")));

			roll.setTubeWeight(Float.parseFloat(request
					.getParameter("tubeWeight")));

			roll.setWasteLength(Float.parseFloat(request
					.getParameter("wasteLength")));

			roll.setWeightingStatus(Boolean.parseBoolean(request
					.getParameter("weightingStatus")));

			roll.setWidth(Float.parseFloat(request.getParameter("width")));

			roll.setWpi(Float.parseFloat(request.getParameter("wpi")));

			// 获取数据库操作对象
			RollDAOImpl rdi = new RollDAOImpl();

			// 更新数据库
			boolean update = false;

			try {
				update = rdi.finishUpdateRoll(roll);
			} catch (Exception e) {
				System.out.print("Finish update Servlet:  执行更新语句未通过" + "\n");
			}

			if (update) {
				System.out.print("Finish update Servlet:  执行更新成功" + "\n\n");
			} else {
				System.out.print("Finish update Servlet:  执行更新失败" + "\n\n");
			}

			// 以防传入参数时便报错
		} catch (Exception e) {
			System.out.print("Finish update request.getparams:  传入参数时出错" + "\n\n");

		}

	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}
